﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace YQGL.DAL
{
    /// <summary>
    /// 数据访问类:DJ_QYZCXX
    /// </summary>
    public partial class DJ_QYZCXX
    {
        public DJ_QYZCXX()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string Qybm)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from DJ_QYZCXX");
            strSql.Append(" where Qybm=@Qybm ");
            SqlParameter[] parameters = {
					new SqlParameter("@Qybm", SqlDbType.VarChar,20)			};
            parameters[0].Value = Qybm;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(YQGL.Model.DJ_QYZCXX model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into DJ_QYZCXX(");
            strSql.Append("Qybm,ZZDM,Nsrsbh,Nsrsbh_DS,Nsrmc,FDDBRMC,FRDHHM,SCJYDZ,JYDZ,TJRMC,TjrDH,Cyrs,CYRS_BK,DXHM,Email,QyGH,QYDL_DM,QYLX_DM,QYLXMX_DM,SDYSX1_DM,SDYSX2_DM,SDYSX3_DM,SDYSX4_DM,SDYSX5_DM,ZTDM,SHR_DM,SHRQ,SHXX,Nsrdzdah,QQHM,FZRMC,FZRDH)");
            strSql.Append(" values (");
            strSql.Append("@Qybm,@ZZDM,@Nsrsbh,@Nsrsbh_DS,@Nsrmc,@FDDBRMC,@FRDHHM,@SCJYDZ,@JYDZ,@TJRMC,@TjrDH,@Cyrs,@CYRS_BK,@DXHM,@Email,@QyGH,@QYDL_DM,@QYLX_DM,@QYLXMX_DM,@SDYSX1_DM,@SDYSX2_DM,@SDYSX3_DM,@SDYSX4_DM,@SDYSX5_DM,@ZTDM,@SHR_DM,@SHRQ,@SHXX,@Nsrdzdah,@QQHM,@FZRMC,@FZRDH)");
            SqlParameter[] parameters = {
					new SqlParameter("@Qybm", SqlDbType.VarChar,20),
					new SqlParameter("@ZZDM", SqlDbType.VarChar,20),
					new SqlParameter("@Nsrsbh", SqlDbType.VarChar,20),
					new SqlParameter("@Nsrsbh_DS", SqlDbType.VarChar,20),
					new SqlParameter("@Nsrmc", SqlDbType.VarChar,80),
					new SqlParameter("@FDDBRMC", SqlDbType.VarChar,20),
					new SqlParameter("@FRDHHM", SqlDbType.VarChar,20),
					new SqlParameter("@SCJYDZ", SqlDbType.VarChar,80),
					new SqlParameter("@JYDZ", SqlDbType.VarChar,80),
					new SqlParameter("@TJRMC", SqlDbType.VarChar,20),
					new SqlParameter("@TjrDH", SqlDbType.VarChar,20),
					new SqlParameter("@Cyrs", SqlDbType.Int,4),
					new SqlParameter("@CYRS_BK", SqlDbType.Int,4),
					new SqlParameter("@DXHM", SqlDbType.VarChar,11),
					new SqlParameter("@Email", SqlDbType.VarChar,50),
					new SqlParameter("@QyGH", SqlDbType.VarChar,1000),
					new SqlParameter("@QYDL_DM", SqlDbType.Char,2),
					new SqlParameter("@QYLX_DM", SqlDbType.Char,4),
					new SqlParameter("@QYLXMX_DM", SqlDbType.VarChar,100),
					new SqlParameter("@SDYSX1_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX2_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX3_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX4_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX5_DM", SqlDbType.Char,2),
					new SqlParameter("@ZTDM", SqlDbType.Char,1),
					new SqlParameter("@SHR_DM", SqlDbType.Char,8),
					new SqlParameter("@SHRQ", SqlDbType.DateTime),
					new SqlParameter("@SHXX", SqlDbType.VarChar,200),
					new SqlParameter("@Nsrdzdah", SqlDbType.VarChar,20),
					new SqlParameter("@QQHM", SqlDbType.VarChar,20),
					new SqlParameter("@FZRMC", SqlDbType.VarChar,20),
					new SqlParameter("@FZRDH", SqlDbType.VarChar,20)};
            parameters[0].Value = model.Qybm;
            parameters[1].Value = model.ZZDM;
            parameters[2].Value = model.Nsrsbh;
            parameters[3].Value = model.Nsrsbh_DS;
            parameters[4].Value = model.Nsrmc;
            parameters[5].Value = model.FDDBRMC;
            parameters[6].Value = model.FRDHHM;
            parameters[7].Value = model.SCJYDZ;
            parameters[8].Value = model.JYDZ;
            parameters[9].Value = model.TJRMC;
            parameters[10].Value = model.TjrDH;
            parameters[11].Value = model.Cyrs;
            parameters[12].Value = model.CYRS_BK;
            parameters[13].Value = model.DXHM;
            parameters[14].Value = model.Email;
            parameters[15].Value = model.QyGH;
            parameters[16].Value = model.QYDL_DM;
            parameters[17].Value = model.QYLX_DM;
            parameters[18].Value = model.QYLXMX_DM;
            parameters[19].Value = model.SDYSX1_DM;
            parameters[20].Value = model.SDYSX2_DM;
            parameters[21].Value = model.SDYSX3_DM;
            parameters[22].Value = model.SDYSX4_DM;
            parameters[23].Value = model.SDYSX5_DM;
            parameters[24].Value = model.ZTDM;
            parameters[25].Value = model.SHR_DM;
            parameters[26].Value = model.SHRQ;
            parameters[27].Value = model.SHXX;
            parameters[28].Value = model.Nsrdzdah;
            parameters[29].Value = model.QQHM;
            parameters[30].Value = model.FZRMC;
            parameters[31].Value = model.FZRDH;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(YQGL.Model.DJ_QYZCXX model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update DJ_QYZCXX set ");
            strSql.Append("ZZDM=@ZZDM,");
            strSql.Append("FDDBRMC=@FDDBRMC,");
            strSql.Append("FRDHHM=@FRDHHM,");
            strSql.Append("SCJYDZ=@SCJYDZ,");
            strSql.Append("JYDZ=@JYDZ,");
            strSql.Append("TJRMC=@TJRMC,");
            strSql.Append("TjrDH=@TjrDH,");
            strSql.Append("Cyrs=@Cyrs,");
            strSql.Append("CYRS_BK=@CYRS_BK,");
            strSql.Append("DXHM=@DXHM,");
            strSql.Append("Email=@Email,");
            strSql.Append("QyGH=@QyGH,");
            strSql.Append("QYDL_DM=@QYDL_DM,");
            strSql.Append("QYLX_DM=@QYLX_DM,");
            strSql.Append("QYLXMX_DM=@QYLXMX_DM,");
            strSql.Append("SDYSX1_DM=@SDYSX1_DM,");
            strSql.Append("SDYSX2_DM=@SDYSX2_DM,");
            strSql.Append("SDYSX3_DM=@SDYSX3_DM,");
            strSql.Append("SDYSX4_DM=@SDYSX4_DM,");
            strSql.Append("SDYSX5_DM=@SDYSX5_DM,");
            strSql.Append("ZTDM=@ZTDM,");
            strSql.Append(" QQHM=@QQHM, ");
            strSql.Append("Nsrsbh=@Nsrsbh,");
            strSql.Append("Nsrsbh_DS=@Nsrsbh_DS,");
            strSql.Append("Nsrmc=@Nsrmc,");
            strSql.Append("FZRMC=@FZRMC,");
            strSql.Append("FZRDH=@FZRDH");
            strSql.Append(" where Qybm=@Qybm ");
            SqlParameter[] parameters = {
					new SqlParameter("@ZZDM", SqlDbType.VarChar,20),
					new SqlParameter("@FDDBRMC", SqlDbType.VarChar,20),
					new SqlParameter("@FRDHHM", SqlDbType.VarChar,20),
					new SqlParameter("@SCJYDZ", SqlDbType.VarChar,80),
					new SqlParameter("@JYDZ", SqlDbType.VarChar,80),
					new SqlParameter("@TJRMC", SqlDbType.VarChar,20),
					new SqlParameter("@TjrDH", SqlDbType.VarChar,20),
					new SqlParameter("@Cyrs", SqlDbType.Int,4),
					new SqlParameter("@CYRS_BK", SqlDbType.Int,4),
					new SqlParameter("@DXHM", SqlDbType.VarChar,20),
					new SqlParameter("@Email", SqlDbType.VarChar,50),
					new SqlParameter("@QyGH", SqlDbType.VarChar,1000),
					new SqlParameter("@QYDL_DM", SqlDbType.Char,2),
					new SqlParameter("@QYLX_DM", SqlDbType.Char,4),
					new SqlParameter("@QYLXMX_DM", SqlDbType.VarChar,1000),
					new SqlParameter("@SDYSX1_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX2_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX3_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX4_DM", SqlDbType.Char,2),
					new SqlParameter("@SDYSX5_DM", SqlDbType.Char,2),
					new SqlParameter("@ZTDM", SqlDbType.Char,1),
					new SqlParameter("@SHR_DM", SqlDbType.Char,8),
					new SqlParameter("@SHRQ", SqlDbType.DateTime),
					new SqlParameter("@SHXX", SqlDbType.VarChar,200),
					new SqlParameter("@Qybm", SqlDbType.VarChar,20),
					new SqlParameter("@Nsrsbh", SqlDbType.VarChar,20),
					new SqlParameter("@Nsrsbh_DS", SqlDbType.VarChar,20),
					new SqlParameter("@Nsrmc", SqlDbType.VarChar,50),
					new SqlParameter("@Nsrdzdah", SqlDbType.VarChar,20),
                                        new SqlParameter("@QQHM", SqlDbType.VarChar,50),
                                        
                                        new SqlParameter("@FZRMC", SqlDbType.VarChar,20),
					new SqlParameter("@FZRDH", SqlDbType.VarChar,20),};
            parameters[0].Value = model.ZZDM;
            parameters[1].Value = model.FDDBRMC;
            parameters[2].Value = model.FRDHHM;
            parameters[3].Value = model.SCJYDZ;
            parameters[4].Value = model.JYDZ;
            parameters[5].Value = model.TJRMC;
            parameters[6].Value = model.TjrDH;
            parameters[7].Value = model.Cyrs;
            parameters[8].Value = model.CYRS_BK;
            parameters[9].Value = model.DXHM;
            parameters[10].Value = model.Email;
            parameters[11].Value = model.QyGH;
            parameters[12].Value = model.QYDL_DM;
            parameters[13].Value = model.QYLX_DM;
            parameters[14].Value = model.QYLXMX_DM;
            parameters[15].Value = model.SDYSX1_DM;
            parameters[16].Value = model.SDYSX2_DM;
            parameters[17].Value = model.SDYSX3_DM;
            parameters[18].Value = model.SDYSX4_DM;
            parameters[19].Value = model.SDYSX5_DM;
            parameters[20].Value = model.ZTDM;
            parameters[21].Value = model.SHR_DM;
            parameters[22].Value = model.SHRQ;
            parameters[23].Value = model.SHXX;
            parameters[24].Value = model.Qybm;
            parameters[25].Value = model.Nsrsbh;
            parameters[26].Value = model.Nsrsbh_DS;
            parameters[27].Value = model.Nsrmc;
            parameters[28].Value = model.Nsrdzdah;
            parameters[29].Value = model.QQHM;
            parameters[30].Value = model.FZRMC;
            parameters[31].Value = model.FZRDH;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string Qybm)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DJ_QYZCXX ");
            strSql.Append(" where Qybm=@Qybm ");
            SqlParameter[] parameters = {
					new SqlParameter("@Qybm", SqlDbType.VarChar,20)			};
            parameters[0].Value = Qybm;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string Qybmlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from DJ_QYZCXX ");
            strSql.Append(" where Qybm in (" + Qybmlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public YQGL.Model.DJ_QYZCXX GetModel(string Qybm)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Qybm,ZZDM,Nsrsbh,Nsrsbh_DS,Nsrmc,FDDBRMC,FRDHHM,SCJYDZ,JYDZ,TJRMC,TjrDH,Cyrs,CYRS_BK,DXHM,Email,QyGH,QYDL_DM,QYLX_DM,QYLXMX_DM,SDYSX1_DM,SDYSX2_DM,SDYSX3_DM,SDYSX4_DM,SDYSX5_DM,ZTDM,SHR_DM,SHRQ,SHXX,Nsrdzdah,QQHM,FZRMC,FZRDH  from DJ_QYZCXX ");
            strSql.Append(" where Qybm=@Qybm ");
            SqlParameter[] parameters = {
					new SqlParameter("@Qybm", SqlDbType.VarChar,20)			};
            parameters[0].Value = Qybm;

            YQGL.Model.DJ_QYZCXX model = new YQGL.Model.DJ_QYZCXX();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public YQGL.Model.DJ_QYZCXX DataRowToModel(DataRow row)
        {
            YQGL.Model.DJ_QYZCXX model = new YQGL.Model.DJ_QYZCXX();
            if (row != null)
            {
                if (row["Qybm"] != null)
                {
                    model.Qybm = row["Qybm"].ToString();
                }
                if (row["ZZDM"] != null)
                {
                    model.ZZDM = row["ZZDM"].ToString();
                }
                if (row["Nsrsbh"] != null)
                {
                    model.Nsrsbh = row["Nsrsbh"].ToString();
                }
                if (row["Nsrsbh_DS"] != null)
                {
                    model.Nsrsbh_DS = row["Nsrsbh_DS"].ToString();
                }
                if (row["Nsrmc"] != null)
                {
                    model.Nsrmc = row["Nsrmc"].ToString();
                }
                if (row["FDDBRMC"] != null)
                {
                    model.FDDBRMC = row["FDDBRMC"].ToString();
                }
                if (row["FRDHHM"] != null)
                {
                    model.FRDHHM = row["FRDHHM"].ToString();
                }
                if (row["SCJYDZ"] != null)
                {
                    model.SCJYDZ = row["SCJYDZ"].ToString();
                }
                if (row["JYDZ"] != null)
                {
                    model.JYDZ = row["JYDZ"].ToString();
                }
                if (row["TJRMC"] != null)
                {
                    model.TJRMC = row["TJRMC"].ToString();
                }
                if (row["TjrDH"] != null)
                {
                    model.TjrDH = row["TjrDH"].ToString();
                }
                if (row["Cyrs"] != null && row["Cyrs"].ToString() != "")
                {
                    model.Cyrs = int.Parse(row["Cyrs"].ToString());
                }
                if (row["CYRS_BK"] != null && row["CYRS_BK"].ToString() != "")
                {
                    model.CYRS_BK = int.Parse(row["CYRS_BK"].ToString());
                }
                if (row["DXHM"] != null)
                {
                    model.DXHM = row["DXHM"].ToString();
                }
                if (row["Email"] != null)
                {
                    model.Email = row["Email"].ToString();
                }
                if (row["QyGH"] != null)
                {
                    model.QyGH = row["QyGH"].ToString();
                }
                if (row["QYDL_DM"] != null)
                {
                    model.QYDL_DM = row["QYDL_DM"].ToString();
                }
                if (row["QYLX_DM"] != null)
                {
                    model.QYLX_DM = row["QYLX_DM"].ToString();
                }
                if (row["QYLXMX_DM"] != null)
                {
                    model.QYLXMX_DM = row["QYLXMX_DM"].ToString();
                }
                if (row["SDYSX1_DM"] != null)
                {
                    model.SDYSX1_DM = row["SDYSX1_DM"].ToString();
                }
                if (row["SDYSX2_DM"] != null)
                {
                    model.SDYSX2_DM = row["SDYSX2_DM"].ToString();
                }
                if (row["SDYSX3_DM"] != null)
                {
                    model.SDYSX3_DM = row["SDYSX3_DM"].ToString();
                }
                if (row["SDYSX4_DM"] != null)
                {
                    model.SDYSX4_DM = row["SDYSX4_DM"].ToString();
                }
                if (row["SDYSX5_DM"] != null)
                {
                    model.SDYSX5_DM = row["SDYSX5_DM"].ToString();
                }
                if (row["ZTDM"] != null)
                {
                    model.ZTDM = row["ZTDM"].ToString();
                }
                if (row["SHR_DM"] != null)
                {
                    model.SHR_DM = row["SHR_DM"].ToString();
                }
                if (row["SHRQ"] != null && row["SHRQ"].ToString() != "")
                {
                    model.SHRQ = DateTime.Parse(row["SHRQ"].ToString());
                }
                if (row["SHXX"] != null)
                {
                    model.SHXX = row["SHXX"].ToString();
                }
                if (row["Nsrdzdah"] != null)
                {
                    model.Nsrdzdah = row["Nsrdzdah"].ToString();
                }

                if (row["QQHM"] != null)
                {
                    model.QQHM = row["QQHM"].ToString();
                }

                if (row["FZRMC"] != null)
                {
                    model.FZRMC = row["FZRMC"].ToString();
                }
                if (row["FZRDH"] != null)
                {
                    model.FZRDH = row["FZRDH"].ToString();
                }
            }
            return model;
        }

        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Qybm,ZZDM,Nsrsbh,Nsrsbh_DS,Nsrmc,FDDBRMC,FRDHHM,SCJYDZ,JYDZ,TJRMC,TjrDH,Cyrs,CYRS_BK,DXHM,Email,QyGH,QYDL_DM,QYLX_DM,QYLXMX_DM,SDYSX1_DM,SDYSX2_DM,SDYSX3_DM,SDYSX4_DM,SDYSX5_DM,ZTDM,SHR_DM,SHRQ,SHXX,Nsrdzdah,QQHM,FZRMC,FZRDH  ");
            strSql.Append(" FROM DJ_QYZCXX ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" Qybm,ZZDM,Nsrsbh,Nsrsbh_DS,Nsrmc,FDDBRMC,FRDHHM,SCJYDZ,JYDZ,TJRMC,TjrDH,Cyrs,CYRS_BK,DXHM,Email,QyGH,QYDL_DM,QYLX_DM,QYLXMX_DM,SDYSX1_DM,SDYSX2_DM,SDYSX3_DM,SDYSX4_DM,SDYSX5_DM,ZTDM,SHR_DM,SHRQ,SHXX,Nsrdzdah,QQHM ");
            strSql.Append(" FROM DJ_QYZCXX ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM DJ_QYZCXX ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.Qybm desc");
            }
            strSql.Append(")AS Row, T.*  from DJ_QYZCXX T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "DJ_QYZCXX";
            parameters[1].Value = "Qybm";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

